package org.nci.platform.workflow.service.impl;

import gh.priv.general.common.vo.PageResult;
import org.nci.platform.workflow.dto.SysFormPageQuery;
import org.nci.platform.workflow.dto.SysFormQuery;
import org.nci.platform.workflow.entity.SysForm;
import org.nci.platform.workflow.mapper.SysFormMapper;
import org.nci.platform.workflow.service.FlowableMapperService;
import org.nci.platform.workflow.service.ISysFormService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程表单Service业务层处理
 *
 * @author Tony
 * @date 2021-04-03
 */
@Service
public class SysFormServiceImpl implements ISysFormService {
    @Resource
    private FlowableMapperService flowableMapperService;

    @Override
    public SysForm getById(long id) {
        return flowableMapperService.executeQuery(SysFormMapper.class, mapper -> mapper.getById(id));
    }

    @Override
    public PageResult<SysForm> page(SysFormPageQuery query) {
        List<SysForm> pageList = flowableMapperService.executeQuery(SysFormMapper.class, mapper -> mapper.page(query));
        Long count = flowableMapperService.executeQuery(SysFormMapper.class, mapper -> mapper.pageCount(query));
        return PageResult.of(pageList, count, query.getPageSize(), query.getPageSize());
    }

    @Override
    public List<SysForm> list(SysFormQuery query) {
        return flowableMapperService.executeQuery(SysFormMapper.class, mapper -> mapper.list(query));
    }

    @Override
    public void export(HttpServletResponse response, SysFormQuery query) {

    }

    @Override
    public void save(SysForm sysForm) {
        flowableMapperService.executeUpdate(SysFormMapper.class, mapper -> mapper.save(sysForm));
    }

    @Override
    public void updateById(SysForm sysForm) {
        flowableMapperService.executeUpdate(SysFormMapper.class, mapper -> mapper.updateById(sysForm));
    }

    @Override
    public void removeByIds(List<Long> formIds) {
        flowableMapperService.executeUpdate(SysFormMapper.class, mapper -> mapper.removeByIds(formIds));
    }
}
